package com.woniuxy.pojo;

import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

// 泛型类    T：代表任何类型
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("响应结果封装类")
public class Result<T> implements Serializable {
    // 返回的状态码：200成功； 500失败
    private Integer code;
    // 返回的提示内容
    private String msg;
    // 返回的数据
    private T obj;

    // 操作成功
    public static <T> Result<T> ok() {
        return new Result<>(200,"操作成功!",null);
    }

    public static <T> Result<T> ok(T obj) {
        return new Result<>(200,"操作成功",obj);
    }
    public static <T> Result<T> ok(T obj,String msg) {
        return new Result<>(200,msg,obj);
    }
    public static <T> Result<T> ok(T obj,String msg,Integer code) {
        return new Result<>(code,msg,obj);
    }
    // 操作失败
    public static <T> Result<T> fail() {
        return new Result<>(500,"操作失败!",null);
    }
    public static <T> Result<T> fail(String msg) {
        return new Result<>(500,msg,null);
    }


}
